package top.zhangjianyong.blog.manage.controller;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.zhangjianyong.blog.annotation.Permission;
import top.zhangjianyong.blog.enums.RoleKeys;
import top.zhangjianyong.blog.params.weibo.*;
import top.zhangjianyong.blog.response.ApiResponse;
import top.zhangjianyong.blog.service.WeiboService;

@RequestMapping("/weibo")
@RestController
@Permission(roles = {RoleKeys.ADMIN})
public class WeiboController {

  private final WeiboService weiboService;

  public WeiboController(WeiboService weiboService) {
    this.weiboService = weiboService;
  }

  @PostMapping("/page")
  public ApiResponse page(@RequestBody @Validated WeiboPageParam param) {
    return weiboService.page(param);
  }

  @PostMapping("/saveOrUpdate")
  public ApiResponse saveOrUpdate(@RequestBody @Validated WeiboSaveOrUpdateParam param) {
    return weiboService.saveOrUpdate(param);
  }

  // 发布
  @PostMapping("/push")
  public ApiResponse push(@RequestBody @Validated WeiboPushParam param) {
    return weiboService.push(param);
  }

  // 删除
  @PostMapping("/remove")
  public ApiResponse remove(@RequestBody @Validated WeiboRemoveParam param) {
    return weiboService.remove(param);
  }

  @PostMapping("/top")
  public ApiResponse top(@RequestBody @Validated WeiboTopParam param) {
    return weiboService.top(param);
  }
}
